package com.mstore.action;

import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;
import org.apache.struts2.interceptor.SessionAware;

import com.mstore.pojo.Account;
import com.mstore.pojo.BFuncPrivilege;
import com.mstore.service.BFuncPrivilegeService;

public class FuncPrivilegeAction extends BaseAction implements SessionAware {

	private static final long serialVersionUID = 1255458140456366381L;

	private BFuncPrivilegeService funcPrivilegeService;

	private String result;

	private Map<String, Object> session;

	/**
	 * 功能id
	 */
	private Long funcId;

	private static Logger logger = Logger.getLogger(FuncPrivilegeAction.class
			.getName());

	public String getFuncPrivilege() {
		Object object = session.get("account");
		if (object == null) {
			result = "系统异常，请重新登陆！";
			return "error";
		}
		Account account = (Account) object;
		
		try {
			List<BFuncPrivilege> funcPrivileges = funcPrivilegeService.getFuncPrivilegeByEaId(account.getId());
			result = listTojson(funcPrivileges);
			return "getFuncPrivilege";
		}
		catch (Exception e) {
			logger.error("功能权限判断报错", e);
		}

		return "error";
	}

	public String getResult() {
		return result;
	}

	public void setResult(String result) {
		this.result = result;
	}

	public BFuncPrivilegeService getFuncPrivilegeService() {
		return funcPrivilegeService;
	}

	public void setFuncPrivilegeService(
			BFuncPrivilegeService funcPrivilegeService) {
		this.funcPrivilegeService = funcPrivilegeService;
	}

	public Long getFuncId() {
		return funcId;
	}

	public void setFuncId(Long funcId) {
		this.funcId = funcId;
	}

	@Override
	public void setSession(Map<String, Object> session) {
		this.session = session;
	}
}
